User
defined graphics demo tool
Description
Demonstrates various user defined graphics capabilities.
Apex has integrated the Visualization Toolkit (VTK) with and exposed
the entire feature of set of VTK to the Apex Python scripting API. This
integration enables authors of custom tools to display of virtually any
graphics representations that VTK is capable of producing directly within the
Apex graphics viewport alongside native Apex objects. User defined graphics
objects are rotated, zoomed, panned and fitted to the viewport using the Apex
view manipulation controls. VTK objects can also be picked and interacted with using
the VTK algorithms and manipulators.
NOTE : This tool is intended to demonstrate how a small subset
of VTK capabilities can be used alongside Apex. The tool has no purpose other
than demonstrating these capabilities, neither is it intended to be a VTK training
course. VTK provides a comprehensive set of demo problems, an excellent
textbook and online API documentation. If you are familiar with VTK, the demos
provided here should provide you with enough information to leverage your VTK capabilities
within Apex.
The sections that follow
describe the scope of each demo. To understand the implementation users are recommended
to review the implementations that ca be found in your custom tools folder.
Each demo description identifies the files that contain the implementation, all
of which can be found in the custom tools folder of your installation ‘~\Custom
Tools XXXX\Demo Tools\UI control and batch tools\UI Control Tools\User
graphics\src’.
If you have any questions about the integration of VTK with
Apex, or if there is a feature of VTK that you would like to see included in these
demos please feel free to contact
doug@cadence.com
or the support team at MSC.
Tool Usage
The tool presents a series of standalone demonstrations, each
initiated from a button on the tool UI shown below. It is advisable to run one
of the demos and then click the “Clear all” button before proceeding to the
next demo. You can choose
not
to clear the preceding demo before
running the next one however this can lead to a very busy graphics
view!!!!
The demos have no
interdependencies and can be run in any order.
1.
Invoke
the tool from the Loads/BC’s group of the Apex Utilities Attribution tool
palette and click on the buttons to run the demo. A brief description of each
demo capability is provided below. You can also inspect the code for each demo
by looking at the implementation files.
2. The “Reset” and “Clear all demos” buttons to not invoke demonstrations.
a. The “Clear all demos” button deletes any graphics objects that are created by the demo tools.
b. The “Reset” button deletes the current user graphics system, replaces it with a new one and redraws any existing graphics objects into the new system
‘Demo spiky sphere’
This demo uses some basic VTK capabilities to,
1.
generate
a facetted sphere
2.
generate
a plane below the sphere
3.
measure
the distance between every point on the sphere and the plane and add that
distance field to sphere “Point data”
4.
calculate
the outward normal vector at every point on the sphere
5.
define
a “3D arrow” glyph
6.
position
instances of the arrow glyph at every point on the surface of the sphere and
orient it along the outward normal
7.
Color
code the sphere and the arrows using the previously calculated distance field
8.
Display
the sphere at the location on the Apex model selected by the user (Or at the global
origin if no point is selected.
This demo is implemented
in the file ‘sphere_spiky.py’ that can be found in the ‘~\Custom Tools XXXX\Demo
Tools\UI control and batch tools\UI Control Tools\User graphics\src’ folder of
your custom tools folder.
‘Demo cow’
This demo uses a VTK reader to read a VTK file (vtkPolyData)
containing a tessellated model of a cow and display it on the Apex graphics
view.
The tessellation is drawn centered on any selected point in the
Apex model or centered on the global origin if no Apex entities are selected.
This demo is implemented
in the file ‘cow.py’ that can be found in the ‘~\Custom Tools XXXX\Demo
Tools\UI control and batch tools\UI Control Tools\User graphics\src’ folder of
your custom tools folder.
‘Demo spline’
This demo uses VTK to generate a spline through the set of
points that are selected by the user. The spline is drawn as a simple line and
a small sphere is drawn at each input location using a single sphere which is
instanced to every input point using the VTK 3D glyph mapping functionality.
NOTE : The order of the input points is not preserved during
spline creation.
If no input points are provided a spline will be generated
between three predefined point locations.
This demo is implemented
in the file ‘spline.py’ that can be found in the ‘~\Custom Tools XXXX\Demo
Tools\UI control and batch tools\UI Control Tools\User graphics\src’ folder of
your custom tools folder.
‘Demo spline as tube’
This demo extends the previous demo by rendering the spline as a
constant radius tube. VTK provides capabilities to render any kind of line as a
tube using a single display parameter.
This demo is implemented
in the same ‘spline.py’ as the previous example which can be found at in the ‘~\Custom
Tools XXXX\Demo Tools\UI control and batch tools\UI Control Tools\User
graphics\src’ folder of your custom tools folder.
‘Demo snowman’
This demo shows how models defined in .obj files can be included
in the Apex graphics view. The demo includes the use of some very basic
texturing and physically based rendering techniques to give these very low poly
count models a richer appearance.
This demo is implemented
in the file ‘snowman.py’ which can be found at in the ‘~\Custom Tools XXXX\Demo
Tools\UI control and batch tools\UI Control Tools\User graphics\src’ folder of
your custom tools folder.
‘Create drone arm’
This demo shows how to display a tetrahedral mesh in the Apex
graphics view. The mesh is read from a VTK formatted file (vtkUnstructuredGrid)
that includes the definition of the nodal coordinates and tetrahedral elements
as well as a nodal displacement vector field. The demo includes user interact
with the mesh using the keyboard and an on screen slider that controls the
shrink ratio of the elements.
The demo includes the following features,
1.
the mesh
and displacement field are imported using a VTK reader
2.
the free
faces of the tetrahedral mesh are extracted prior to display
3.
the node
IDs, tetrahedral element IDs and displacement vector field are transferred from
the 3D to the 2D representation as part of the free face extraction
4.
the model
is color codes using eth resultant of the displacement vector field
5.
a “Scalar
bar” is displayed at the bottom of the Apex view to indicate key values of the
color coding
6.
The
render style can be changed to wireframe by pressing the “w” or ‘W’ key
7.
The
render style can be toggled between shaded and shaded with edges by pressing
the ‘s’ or ‘S’ key
8.
A slider
bar is displayed that can be used to shrink the element display. Each element
us shrunk about its centroid. The slider bar is an example of an interact 3D VTK
Widget. VTK provides a suite of useful 3D widgets – refer to the VTK textbook
for examples.
9.
An interactive
probe can be used to display the displacement field value, ids and location of
the nodes in the model. Hit the ‘v’ key and move the cursor over the model to
display the data.
a.
The
probe includes a highlight sphere to provide visual indication of the location
of the node that is being probed. The size of this sphere can be increased/decreased
interactively using the ‘d’ and ‘r’ keys respectively
b.
The
probe uses a radial tolerance to find the nodes. The tolerance can be
increased/decreased interactively using the ‘+’ and ‘-‘ keys
This demo is implemented
in the file ‘drone_hybrid.py’ which can be found at in the ‘~\Custom Tools XXXX\Demo
Tools\UI control and batch tools\UI Control Tools\User graphics\src’ folder of
your custom tools folder.
‘Create sphere’
This demo displays a facetted sphere in the Apex display. The sphere
is generated using a vtkSphereSource, the edges of the tessellation are displayed
as tubes and the points as spheres using built in VTK functionality
This demo is implemented
in the file ‘sphere_and_tube.py’ which can be found at in the ‘~\Custom Tools XXXX\Demo
Tools\UI control and batch tools\UI Control Tools\User graphics\src’ folder of
your custom tools folder.
‘Create chart on
scene’
This demo shows how to display an XY chart superimposed on the Apex
graphics view
This demo is implemented
in the file ‘chart_on_3D_scene.py’ which can be found at in the ‘~\Custom Tools
XXXX\Demo Tools\UI control and batch tools\UI Control Tools\User graphics\src’
folder of your custom tools folder.
‘Create Box Widget
This demo shows how to display and manipulate a VTK Box widget
on the Apex graphics view. The vtkBoxWidget is an example of a VTK interactive
3D widget. This widget provides ‘handles’ at the centroid of each face of the
box representation. These handles can be dragged to change the dimensions of
the box and the box dimensions are used to scale the target – in this case a
simple graphical cone.
WARNING
: This demo may fail to work correctly if it
is invoked for a second time after previously clearing it with the “Clear all demos”
tool.
WARNING
: It is inadvisable to run this dem at the
same time as the “Create drone arm” demo. Some (currently unresolved) conflict
arises between the Box Widget interaction and the SliderWidget
This demo is implemented
in the file ‘box_wdiget.py’ which can be found at in the ‘~\Custom Tools XXXX\Demo
Tools\UI control and batch tools\UI Control Tools\User graphics\src’ folder of
your custom tools folder.
‘Demo simple
animation’
This demo shows how to perform basic animation in the Apex graphics
view using VTK.
The tool initial displays a sphere from a previous example.
Pressing the ‘A” key initiates the animation
This demo is implemented
in the file ‘simple_animation.py’ which can be found at in the ‘~\Custom Tools XXXX\Demo
Tools\UI control and batch tools\UI Control Tools\User graphics\src’ folder of
your custom tools folder.
‘Demo fringe deform
animation’
This demos sows how to animate a finite element mesh using a
nodal vector field of displacements while using the same field to color code
the display. The demo uses the same models as the “Demo drone arm” tool.
This demo is implemented
in the file ‘fringe_deform_animation.py’ which can be found in the ‘~\Custom
Tools XXXX\Demo Tools\UI control and batch tools\UI Control Tools\User
graphics\src’ folder of your custom tools folder.
VTK implementation
guide
The vast majority of the work required to include user defined
graphics in your custom tool can be re-used directly from standalone VTK
implementations with very little modification required to adapt to Apex.
VTK is based on a pipeline content. Data “sources” (including
readers) can be connected to a sequence of “filters” that modify the source geometry.
This section of the pipeline is referred to by VTK as the “geometry pipeline” and
it’s use in Apex is identical to standalone VTK usage.
When all geometry modifications are complete the display ready
geometry is passed to the “render pipeline which consist of a “mapper” which is
connected to an “actor”. One or more actors can then be added to a “renderer” which
is displayed within a render window. To enable interaction (keyboard, mouse) with
the VTK geometry an “interactor” is created and initialized with the render
window.
Using VTK in Apex requires a slightly different rendering pipeline
compared to the standalone VTK rendering pipeline. A typical standalone
rendering pipeline is shown below
self
.
renderer
=
vtkRenderer
()
self
.
renwin
=
vtkRenderWindow
()
self
.
renwin
.
AddRenderer
(
self
.
renderer
)
self
.
interactor
=
vtkRenderWindowInteractor
()
self
.
interactor
.
SetRenderWindow
(
self
.
renwin
)
The equivalent pipeline in Apex is shown below
self
.
vtkWidget
=
apex.display.getExternalVTKWidget()
self
.
renderer
=
self
.
vtkWidget.AddRenderer()
self
.
renwin
=
self
.
vtkWidget
.GetRenderWindow().GetInteractor()
The key differences are,
1.
Use apex.display.getExternalVTKWidget()
to access the Apex graphics window. instead of instantiating a vtkRenderWindow directly.
The object returned by this method is an ExternalVTKWidget which is effectively
an Apex wrapper around a vtkRenderWindow from which a vtkRenderWindow can be retrieved
if required.
2.
Use the
“AddRenderer()” method of the ExternalVTKWidget instance to create a vtkRenderer
instead of instantiating one directly. Note that this method returns a new
instance of a renderer each time it is . called so you may wish to cache and
re-use the renderer
3.
Use the
“GetRenderWindow()” method of the ExternalVTKWidget instance to retrieve a
vtkRenderWindow and from that render window us the
“GetInteractor()” method to retrieve a vtkInteractor
instead of instantiating a vtkRenderWindowInteractor() directly.
- Log in to post comments